package milkyway.hightech.money;

import java.math.BigInteger;

/**
 *
 * @author Sanim
 */
public class Money
{

    /**
     * The amount of money of this moneyobject.
     */
    private BigInteger value = new BigInteger("0");
    private Currency currency;

    /**
     * Constructor.
     * @param betrag
     * @param currency
     */
    public Money(BigInteger betrag, Currency currency)
    {
        this.value = betrag;
        this.currency = currency;
    }

    /**
     *
     * @param money the value to add.
     * @return new money
     */
    public final Money add(final Money money)
    {
        return new Money(this.value.add(money.value), currency);
    }

    /**
     * returns a new subtracted money object.
     * @param money the value to subtract
     * @return a subtracted money object
     */
    public final Money subtract(final Money money)
    {
        return new Money(this.value.subtract(money.value), currency);
    }

    /**
     * @param obj
     * @return boolean
     */
    @Override
    public boolean equals(Object obj)
    {
        if (obj instanceof Money)
        {
            Money money = (Money)obj;
            
            if (this.value.equals(money.value))
            {
                return true;
            }
        }

        return false;
    }

    /**
     *
     * @param obj
     * @return boolean
     */
    public boolean greater(Object obj)
    {
        if (obj instanceof Money)
        {
            Money money = (Money)obj;

            if (this.value.compareTo(money.value) > 0)
            {
                return true;
            }
        }

        return false;
    }

    /**
     *
     * @param obj
     * @return boolean
     */
    public boolean less(Object obj)
    {
        if (obj instanceof Money)
        {
            Money money = (Money)obj;

            if (this.value.compareTo(money.value) < 0)
            {
                return true;
            }
        }

        return false;
    }

    /**
     *
     * @return
     */
    public BigInteger getValue()
    {
        return value;
    }

    /**
     *
     * @return
     */
    public Currency getCurrency()
    {
        return currency;
    }
}